package demo4;

import java.util.*;

@SuppressWarnings({"all"})
public class test {
    public static void main(String[] args) {
        Map map = new HashMap();
        map.put("no1","hsp");
        map.put("no2","zzy1");
        map.put("no3","zzy2");
        map.put("no4","zzy3");
        Set set = map.keySet();
        System.out.println("第一个遍历的方式：");
        for (Object key : set) {
            System.out.println(map.get(key));
        }

        System.out.println("第二个遍历的方式：");
        Iterator iterator = set.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(map.get(next));
        }

        System.out.println("使用for取出来value数值：");
        Collection values = map.values();

        for (Object value : values) {
            System.out.println(value);
        }

        System.out.println("迭代器取出来这个values数值");
        Iterator iterator1 = values.iterator();
        while (iterator1.hasNext()) {
            Object next =  iterator1.next();
            System.out.println(next);
        }

        Set entryset = map.entrySet();
        System.out.println("使用entryset方法");
        for (Object entry : entryset) {
            Map.Entry m=(Map.Entry) entry;
            System.out.println(m.getKey()+"---"+m.getValue());
        }

        System.out.println("使用entryset迭代器的方法");
        Iterator iterator2 = entryset.iterator();
        while (iterator2.hasNext()) {
            Object entry =  iterator2.next();
            Map.Entry m=(Map.Entry) entry;
            System.out.println(m.getKey()+"---"+m.getValue());
        }
    }
}
